package com.villaday.idf.custom.pop;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.view.View;
import android.view.animation.Animation;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.util.PopularUtil;
import com.villaday.idf.util.ToastUtil;

import razerdp.basepopup.BasePopupWindow;

import static android.content.Context.CLIPBOARD_SERVICE;

public class PhonePopular extends BasePopupWindow {

    private Context mContext;


    public PhonePopular(final Context context, String name, final String phone) {
        super(context);
        mContext = context;

        setBackground(0);
        setOutSideDismiss(true);
        setKeepSize(true);
        setPopupFadeEnable(false);
        setBackgroundColor(Color.parseColor("#B3000000"));
        setBlurBackgroundEnable(true);
//        findViewById(R.id.ll_phone).startAnimation(PopularUtil.buildAnimal());
        TextView tvName = findViewById(R.id.tv_phone_name);
        tvName.setText("对接商务：" + name);

        TextView tvPhoneNum = findViewById(R.id.tv_phone);
        tvPhoneNum.setText(phone);


        TextView tvPhone = findViewById(R.id.tv_phone_phone);
        tvPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(Intent.ACTION_DIAL);
                Uri data = Uri.parse("tel:" + phone);
                intent1.setData(data);
                mContext.startActivity(intent1);
                dismiss();
            }
        });

        //复制
        TextView tvCopy = findViewById(R.id.tv_phone_copy);
        tvCopy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.initToast(context, "已复制号码");
                ClipboardManager mClipboardManager = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
                ClipData mClipData = ClipData.newPlainText("test", phone);
                mClipboardManager.setPrimaryClip(mClipData);
                dismiss();
            }
        });
    }

    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.popular_phone);
    }


    @Override
    protected Animation onCreateShowAnimation() {
        return PopularUtil.ShowAnimation();
    }

    @Override
    protected Animation onCreateDismissAnimation() {
        return PopularUtil.dismissAnimation();
    }
}
